Day 17 - Regular expressions - Groups

59

be impossible to express in a single run without the OR operator, and without the support of a group

I would have to repeat part of the expression twice. Always remember that duplicated code is evil,

even in regular expressions.

Exercises

Exercises! Groups can be complex sometimes, so testing your knowledge can’t but be beneficial.

Remember that you can always write regular expressions in an incremental way, adding pieces and

testing what they do (maybe adding the occasional head to avoid getting too many output lines)

Exercise 17.01

Extract all the lines of simple.log that contain an HTTP method GET or POST, rewrite each line in

the form <time> <HTTP status> <HTTP method>. The result for the first 10 lines should be

10:05:03 200 GET

10:05:43 200 GET

10:05:47 200 GET

10:05:12 200 GET

10:05:07 200 GET

10:05:34 200 GET

10:05:57 200 GET

10:05:50 200 GET

10:05:24 200 GET

10:05:50 200 GET

Go to solution

Exercise 17.02

The file simple.log contains lines with requests concerning files like

83.149.9.216 [17/May/2015:10:05:03 GET /presentations/logstash-monitorama-2013/image\

s/kibana-search.png HTTP/1.1 200 203023 http://semicomplete.com/presentations/logsta\

sh-monitorama-2013/

Extract a list of all file extensions and count them. Assume that extensions are made of lowercase

letters only.

Go to solution